﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.SharePoint;

namespace SharePoint.SPSilver
{
    /// <summary>
    /// represents the original SharePoint SPContentType with all its fields
    /// </summary>
    public class ContentType
    {
        public ContentType(SPContentType type)
        {
            Fields = type.Fields;
            Name = type.Name;
        }
        /// <summary>
        /// these are the full set of SPFields in the SPContentType
        /// </summary>
        public SPFieldCollection Fields { get; set; }

        /// <summary>
        /// The original ContentType Name
        /// </summary>
        public string Name { get; set; }

        /// <summary>
        /// returns the ContentType Name
        /// </summary>
        /// <returns></returns>
        public override string ToString()
        {
            return Name;
        }
        public String Title
        {
            get
            {
                StringBuilder sb = new StringBuilder();
                foreach (SPField f in Fields)
                {
                    sb.AppendFormat(".{0}", f.Title);
                }
                return String.Format("{0}{1}", Name, sb.ToString());
            }
        }
        public bool Equals(ContentType obj)
        {
            if (obj == null)
            {
                if (this == null)
                {
                    return true;
                }
                else
                {
                    return false;
                }
            }
            return this.Title.Equals(obj.Title);
        }
        /*
        public static bool operator ==(ContentType obj0, ContentType obj1)
        {
            return obj0.Title == obj1.Title;
        }
        public static bool operator !=(ContentType obj0, ContentType obj1)
        {
            if (obj0 == null)
                if (obj1 == null)
                    return true;
                else
                    return false;
            if (obj1 == null)
                return false;
            return obj0.Title != obj1.Title;
        }*/
    }
}
